package com.education.welco.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.education.common.core.BaseController;
import com.education.common.utils.ApiReturnObject;
import com.education.welco.pojo.TClass;
import com.education.welco.pojo.TGrade;
import com.education.welco.service.ITGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 年级 信息操作处理
 *
 * @author d
 * @date 2020-05-08
 */
@RestController
@RequestMapping("/tGrade")
public class TGradeController  {

    @Autowired
    private ITGradeService gradeService;

    //查询班级列表   班级名称 上级系的名称
    @GetMapping("/list")
    public ApiReturnObject list(TGrade grade,Integer pageNum,Integer pageSize){
        if(pageNum != null && pageSize != null){
            PageHelper.startPage(pageNum,pageSize);
        }
        List<TGrade> tGrades = gradeService.selectTGradeList(grade);
        PageInfo<TGrade> pageInfo = new PageInfo<>(tGrades);
        return new ApiReturnObject("200","查询成功",pageInfo);
    }


    //添加    选择
    @PostMapping("/add")
    public ApiReturnObject add(@RequestBody TGrade grade ){
        grade.setCreateTime(new Date());
        gradeService.insertTGrade(grade);
        return new ApiReturnObject("200","添加成功","");
    }

    //修改
    @PostMapping("/update")
    public ApiReturnObject update(@RequestBody TGrade grade){
        gradeService.updateTGrade(grade);
        return new ApiReturnObject("200","修改成功","");
    }


    //删除
    @GetMapping("/del")
    public ApiReturnObject del(String ids){
        gradeService.deleteTGradeByIds(ids);
        return new ApiReturnObject("200","删除成功","");
    }


    


}